package com.sanjiahantang.ythshopping.activity.me;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.sanjiahantang.ythshopping.R;
import com.sanjiahantang.ythshopping.activity.BaseActivity;
import com.sanjiahantang.ythshopping.model.ShipMsg;
import com.sanjiahantang.shopping.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.shopping.uilibrary.adapter.listview.QuickAdapter;

import java.util.List;

/**
 * Created by sks on 2015/10/10.
 * 配送方式
 */
public class DistributionActivity extends BaseActivity implements View.OnClickListener,
        AdapterView.OnItemClickListener{
    TextView title;
    ImageView back;
    private Context context;
    private ListView listView;
    private List<ShipMsg> transportlist;
    private QuickAdapter<ShipMsg> quickAdapter;
    @Override
    public void initView() {
        super.initView();
        setContentView(R.layout.activity_selectarea);
        context = this;
        title=(TextView)findViewById(R.id.title);
        back = (ImageView)findViewById(R.id.back);
        title.setText("选择配送方式");
        back.setBackgroundResource(R.mipmap.ic_back);
        findViewById(R.id.fl_Left).setOnClickListener(this);
        listView = (ListView) findViewById(R.id.listView);

        transportlist= (List<ShipMsg>) getIntent().getSerializableExtra("transportMsg");


        quickAdapter = new QuickAdapter<ShipMsg>(context,R.layout.distribution_item) {
            @Override
            protected void convert(BaseAdapterHelper helper, ShipMsg item) {
                helper.setText(R.id.txtName,item.getShipping_name());
//                helper.setText(R.id.txtFee,item.getShipping_desc());
            }
        };
        listView.setAdapter(quickAdapter);
        quickAdapter.addAll(transportlist);
        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {


        for (int j=0;j<transportlist.size();j++)
        {
            transportlist.get(j).setPitch(false);

        }
        transportlist.get(i).setPitch(true);

        Intent intent = new Intent();

        setResult(CreateOrderActivity.DISTRIBUTION,intent);
        finish();
    }



    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.fl_Left:
                finish();
                break;
        }
    }
}
